package com.neu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neu.entity.Disease;
import com.neu.service.DiseaseService;
import com.neu.util.JsonResult;
import com.neu.util.ResultCode;





@RestController
@CrossOrigin
@RequestMapping("/his/disease")
public class DiseaseController {
	@Autowired
	private DiseaseService diseaseService;
//		根据疾病分类查询疾病信息 并分页
	@GetMapping("/get_disease")
	public JsonResult<List<Disease>> getdiseaseInfo(int diseCategoryID,int page,int limit) {
		page = (page-1)*limit;
		List<Disease> list = diseaseService.getdiseaseInfo(diseCategoryID,page,limit);
		int total  = diseaseService.getdiseaseInfoTotal(diseCategoryID);
		return new JsonResult<List<Disease>>(200,list,total);		
	}
//	添加疾病信息
	@PostMapping("/add_disease")
	public JsonResult<Boolean> addDisease(@RequestBody Disease disease) {
		boolean save = diseaseService.addDisease(disease);
		if(save) {
			return new JsonResult<Boolean>(200, save,"添加成功");
		}else {
			return new JsonResult<Boolean>(4003, save,"添加失败");
		}
	}
//	批量删除多个
	@PostMapping("/delete_disease_more")
	public JsonResult<Boolean> delDiseaseByIds(@RequestBody Integer [] ids) {
		boolean dels = diseaseService.delDiseaseByIds(ids);
		if(dels) {
			return new JsonResult<Boolean>(ResultCode.SUCCESS,dels);
		}else {
			return new JsonResult<Boolean>(ResultCode.DEL_ERROR,dels);
		}
	}
//	修改疾病信息
	@PostMapping("/update_disease")
	public JsonResult<Boolean> updateDisease(@RequestBody Disease disease) {
		boolean upd = diseaseService.updateDisease(disease);
		if(upd) {
			return new JsonResult<Boolean>(ResultCode.SUCCESS,upd);
		}else {
			return new JsonResult<Boolean>(ResultCode.UPDATE_ERROR,upd);
		}
	}
	
}
